<?php
/**
 * Created by PhpStorm.
 * User: zhangrongxiang
 * Date: 2018/2/11
 * Time: 下午10:44
 */

$array = [ 1, "hello", 1, "world", "hello" ];
//[1] => 2,[hello] => 2,[world] => 1
print_r( array_count_values( $array ) );

function array_icount_values( $array ) {
	$ret_array = array();
	foreach ( $array as $value ) {
		foreach ( $ret_array as $key2 => $value2 ) {
//			echo $key2."--".$value2.PHP_EOL;
			if ( strtolower( $key2 ) == strtolower( $value ) ) {
				$ret_array[ $key2 ] ++;
				continue 2;//continue 当前for循环
			}
		}
		$ret_array[ $value ] = 1;
	}
	
	return $ret_array;
}

//[1] => 2,[hello] => 2,[world] => 1
print_r( array_icount_values( $array ) );

function array_count_values_ci( $array ) {
	$newArray = array();
	foreach ( $array as $values ) {
		if ( ! array_key_exists( strtolower( $values ), $newArray ) ) {
			$newArray[ strtolower( $values ) ] = 0;
		}
		$newArray[ strtolower( $values ) ] += 1;
	}
	
	return $newArray;
}

//[1] => 2,[hello] => 2,[world] => 1
print_r( array_count_values_ci( $array ) );

